package com.parfinex.study.p2.mod201.dao;


import com.parfinex.study.p2.mod201.entity.Employee;
import com.parfinex.study.p2.mod201.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class EmployeeDao {
    //private Object BeanHandler;

    public static List<Employee> queryEmployee(String name, String gender) throws SQLException {

        //1.获取QueryRunner对象
        QueryRunner qr = new QueryRunner(DBUtils.dataSource);
        //2.编写SQL语句
        String sql = "select * from employee where name = ? and gender = ? ";
        //3.执行查询语句(设置参数)
        //List<Employee> employee
        List<Employee> employee = qr.query(sql,new BeanListHandler<Employee>(Employee.class),name,gender);
        //List<Employee> employee = qr.query(sql,new BeanListHandler<Employee>(Employee.class));
        for (Employee employeebs : employee) {
            System.out.println(employee);

        }
        return employee;
    }



}
